package cn.ryh.designpatterndemo.builderpattern;

import java.util.ArrayList;

/**
 * @ClassName CarTemplateMethod
 * @Description 模拟建造者模式
 * @Author RaoYH
 * @Date 2019/4/22
 *
 * 汽车模板
 */
public abstract class CarBuilderPattern {

    //这个参数是各个基本方法执行的顺序
    private ArrayList<String> sequence = new ArrayList<String>();

    // 基本方法
    protected abstract void doSomething();

    // 基本方法
    protected abstract void doAnything();

    //模板方法
   final public void templateMethod() {
       //循环一便，谁在前，就先执行谁
       for(int i=0;i<this.sequence.size();i++){
           String actionName = this.sequence.get(i);
           if(actionName.equalsIgnoreCase("doSomething")){
               this.doSomething();
           }else if(actionName.equalsIgnoreCase("doAnything")){
               this.doAnything();
           }
       }

    }
    //把传递过来的值传递到类内
    final public void setSequence(ArrayList sequence){
        this.sequence = sequence;
    }
}
